#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
int main()
{
	int n;
	int arr[1001][5];
	int sum[1001] = { 0 };
	int count = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d%d", &arr[i][1], &arr[i][2], &arr[i][3]);
		sum[i] = arr[i][1] + arr[i][2] + arr[i][3];
	}
	for (int j = 1; j <= n; j++)
	{
		for (int i = j + 1; i <= n; i++)
		{
			if (abs(arr[j][1] - arr[i][1]) <= 5 &&
				abs(arr[j][2] - arr[i][2]) <= 5 &&
				abs(arr[j][3] - arr[i][3]) <= 5 &&
				abs(sum[j] - sum[i]) <= 10)
				count++;
		}
	}
	printf("%d", count);
	return 0;
}